package com.ty.enums;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Optional;

public enum PriceStatus {
    NORMAL(1,"售卖"),
    DELETE(0,"历史");

    @Getter @Setter
    private int code;
    @Getter @Setter
    private String message;

    PriceStatus(int code,String message){
        this.code = code;
        this.message =message;
    }

    public static PriceStatus getByCode(int code){
        PriceStatus[] values = PriceStatus.values();
        //jdk1.8 “新”特性 stream流
        //jdk1.8 “新”特性 Optional
        Optional<PriceStatus> first = Arrays.stream(values).filter(item ->  item.getCode() ==code).findFirst();
        //        if( first.isPresent()){ //如果这个Optional容器里面有值，就返回 get() 返回容器里面的值
//            return first.get();
//        }
//        return null;
        return first.orElse(null);
    }
}
